home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-04-16 | 1.5 KB | 61 lines | [TEXT/CWIE] |
- // IAMutex.h
- // Copyright: © 1994 - 1998 by Apple Computer, Inc., all rights reserved.
-
-
- // Interface to mutexes (MUtual EXclusion semaphors) used by IA library.
- // Applications simply subclass IAMutex and set IANewMutex
- // to make IA code thread-safe for the application's threads.
-
- #pragma once
- #ifndef IAMutex_h
- #define IAMutex_h
-
- #pragma import on
-
- #if PRAGMA_STRUCT_ALIGN
- #pragma options align=power
- #endif
-
- #include "IACommon.h"
-
- #include <stdlib.h>
-
- #pragma IA_BEGIN_EXPORTS
-
- class IAMutex { // base class for mutexes
- public:
- virtual ~IAMutex(); // no-op
- virtual void Lock() = 0; // returns when we have control of the mutex
- virtual void Unlock() = 0; // releases control of the mutex
- };
-
- typedef IAMutex* IAMutexConstructor();
- IAMutex* IADefaultMutexConstructor(); // no-op mutex implementation
-
- // IANewMutex is used by IA code to create new mutexes.
- // Applications should reset this to use a different mutex implementation.
- // By default it is set to &IADefaultMutexConstructor, appropriate for single-threaded apps.
- extern IAMutexConstructor* IANewMutex;
-
- // Locks a mutex for the duration of its stack-allocated life.
- // The typical usage is:
- // { IALock lock(mutex);
- // ... code that needs to run locked ... }
- class IALock {
- public:
- IALock(IAMutex* mutex); // locks the mutex
- ~IALock(void); // unlocks the mutex
- private:
- IAMutex *mutex;
- void* operator new(size_t size); // stack allocate only
- };
-
- #pragma IA_END_EXPORTS
-
- #if PRAGMA_STRUCT_ALIGN
- #pragma options align=reset
- #endif
-
- #pragma import reset
- #endif
-